<?php

namespace app\index\validate;

use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'    =>    ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'name|姓名' => 'token|require|length:2,20',
        'email|邮箱' => 'require|email|unique:user',
        'mobile|手机' => 'require|mobile|unique:user',
        'password|密码' => 'require|alphaNum|length:3,20|confirm',

    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'    =>    '错误信息'
     *
     * @var array
     */
    protected $message = [
        'name.require' => '亲,请告诉我们您的名字,哦',
        'name.length' => '名字需要要是2,20个字哦',
        'email.unique' => '这个邮箱貌似已经注册过了',
        'mobile.unique' => '这个手机貌似已经注册过了',
        'password.length' => '密码要3-20字符哦',
    ];


    /**
     * 更新时验证
     *
     */

//    protected $scene = [
//        'update' => ['email','mobile','password'],
//
//        ];

public function sceneUpdate(){
    return $this->only(['name','email','mobile'])
        ->remove('name',['token']);
}

/**
 * 登录时验证
 *
 */

public function sceneLoginCheck()
{
    return $this->only(['name','password'])
//        ->remove('name',['token'])
        ->remove('password',['confirm']);
}


}
